import React, { PureComponent, Fragment } from 'react';
import { connect } from 'dva';
import { Button } from 'antd';
import PageHeaderLayout from '../../layouts/PageHeaderLayout';
import ListTable from "./Components/ListTable";
import PathAdd from "./Components/PathAdd";



@connect(({ global }) => ({
  // dictionaries:global.dictionaries,
  selectSource:global.selectSource,
}))

export default class PathList extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      modalPathAddVisible: false,
      // detailId: 0,
      detailInfoId: 0,
      detailInfoName:null,
      isReloadList:false,
    };
  }


  componentWillUnmount(){
    const { dispatch } = this.props;
    dispatch({
      type: `path/appendClearState`,
    })
  }

  componentDidMount() {
    const { dispatch } = this.props;
    // 数据字典
    // dispatch({
    //   type: 'global/fetch_dictionar',
    //   // payload:["devType", "status", "whitelistReason"]
    // });
    // 维保单位列表
    dispatch({
      type: 'global/fetch_select_maintencompany',
    });
  }

  // 暂停数据回拉
  sotpReloadList = () =>{
    this.setState({
      isReloadList:false,
    });
  }

  // 显示新增修改model
  handlePathModalVisible= flag => {
    this.setState({
      modalPathAddVisible: !!flag,
    });
  };

  // 设备新增、编辑后model回调
  handlePathModelCallBack=()=>{
    this.handlePathModalVisible(false);
    this.setState({
      isReloadList:true,
    });
  }

  // 编辑设备
  handleEditPath = id => {
    this.setState(
      {detailInfoId: id},
      () => {
        this.handlePathModalVisible(true);
      }
    );
  };

  // 展示详情
  handlePathInfo= (id,name) => {
    this.setState(
      {
        detailInfoId: id,
        detailInfoName:name
      }
    );
  };




  render() {
    const { selectSource, location } = this.props;
    const { modalPathAddVisible, detailInfoId, isReloadList } = this.state;
    const pagesquery = location.query;


    return (

          <PageHeaderLayout >
            <ListTable
              // dictionaries={dictionaries}
              selectSource={selectSource}
              addModelCallBack={this.handleEditPath}
              detailModelCallBack={this.handlePathInfo}
              sotpReloadList={this.sotpReloadList}
              isReloadList={isReloadList}
              pagesquery={pagesquery}
              detailId={detailInfoId}
            />

            <PathAdd
              visible={modalPathAddVisible}
              onCancel={e => this.handlePathModalVisible(e)}
              callback={this.handlePathModelCallBack}
              detailId={detailInfoId}
              // dictionaries={dictionaries}
              // selectSource={selectSource}
            />
          </PageHeaderLayout>


    );
  }
}
